package cn.monkey.transport.netty.server.codec.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.util.ReferenceCountUtil;

public class UnsupportedByteBufMsgException extends RuntimeException {
    private final byte[] bytes;

    public UnsupportedByteBufMsgException(byte[] bytes) {
        this.bytes = bytes;
    }

    public UnsupportedByteBufMsgException(ByteBuf byteBuf, boolean release) {
        this.bytes = byteBuf.array();
        if (release) {
            ReferenceCountUtil.release(byteBuf);
        }
    }

    public byte[] bytes() {
        return bytes;
    }

    public UnsupportedByteBufMsgException(ByteBuf byteBuf) {
        this(byteBuf, true);
    }
}
